<?php

/** 
 * @author Administrator
 * 
 * 
 */
include_once S_ROOT."./source/db/db_user.php";
class act_user {
	private $db_user;
	function __construct() {
		$this->db_user = new db_user();
	}
	public function check_usernameexists($username) {
		if($this->db_user->get_userinfo($username))
			return true;
		else
			return false;
	}
	
	public static function check_username($username) {
		$guestexp = '\xA1\xA1|\xAC\xA3|^Guest|^\xD3\xCE\xBF\xCD|\xB9\x43\xAB\xC8';
		$len = strlen($username);
		if($len > 15 || $len < 3 || preg_match("/\s+|^c:\\con\\con|[%,\*\"\s\<\>\&]|$guestexp/is", $username)) {
			return FALSE;
		} else {
			return TRUE;
		}
	}
	
	public 	static function check_usernamecensor($username) {
		$forbituser = array('admin','administrator','root','管理员','paike','拍客宝');
		if(in_array($username,$forbituser))
			return true;
		else 
			return false;
	}
	
	public function register_user($username,&$pwd,$mobile='')
	{
		global $_SGLOBAL;
		$salt = substr(uniqid(rand()), -6);
		$password = md5(md5($pwd).$salt);
		$setarr = array('username'=>$username,'password'=>$password,'mobile'=>$mobile,
				'regtime'=>$_SGLOBAL['timestamp'],'regip'=>getonlineip(),'salt'=>$salt);
		$pwd = $password;
		return $this->db_user->add_user($setarr);
	}
}

?>